package com.qy.common;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import flexjson.JSONSerializer;

public class AbstractController {

	
	/**
	 * 打印text数据
	 * @param xml
	 * @param response
	 */
	public void printTextData(String text,HttpServletResponse response){
		
		ServletUtils.setTextAjaxResponseHeader(response); 
		
		PrintWriter pw;
		try {
			pw = response.getWriter();
			pw.print(text);   
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}    
	}
	
	/**
	 * object 转json
	 * @param response
	 */
	public void printJsonObjectData(Object obj,HttpServletResponse response){
		ServletUtils.setJsonAjaxResponseHeader(response); 
		PrintWriter pw;
		try {
			pw = response.getWriter();
			pw.print((new JSONSerializer()).serialize(obj));   
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}    
	}
}
